use core::{cell::UnsafeCell, ffi::c_void, mem::MaybeUninit, slice, usize};



#[repr(align(8))]
pub struct Store<const SIZE: usize> {
    _buf: [MaybeUninit<UnsafeCell<u8>>; SIZE],
}

unsafe impl<const SIZE: usize> Send for Store<SIZE> {}
unsafe impl<const SIZE: usize> Sync for Store<SIZE> {}

impl <const SIZE: usize> Store<SIZE> {

    const V: MaybeUninit<UnsafeCell<u8>> = MaybeUninit::uninit();

    pub const fn const_new() -> Self {
        Self { _buf: [Self::V; SIZE] }
    }

    pub const fn c_ptr(&self) -> *mut c_void {
        self as *const Self as *mut Self as _
    }

    pub fn slice(&self, index: usize, len: usize) -> &[u8] {
        unsafe {
            slice::from_raw_parts(
                (self.c_ptr() as *const u8).add(index),
                len
            )
        }
    }

    pub fn address(&self) -> u32 {
        self.c_ptr() as u32
    }

    pub const fn len(&self) -> usize {
        SIZE
    }
}






